package jk.zmn.proxy.proxyclass;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;


public class CglibProxy implements MethodInterceptor{

	private Enhancer enhancer = new Enhancer();
	
	public Object getProxyInstance(Class clazz){
		enhancer.setSuperclass(clazz);
		enhancer.setCallback(this);
		return enhancer.create();
	}
	
	
	
	@Override
	public Object intercept(Object object, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		System.out.println("我是日志：是前置处理");
		//通过代理子类来调用父类的方法
		Object invoke = proxy.invokeSuper(object, args);
		System.out.println(args.toString());
		return invoke;
	}

	public void log(Method method, Object[] args) {
		System.out.println("我是日志：添加");
	}
	
	
}
